package com.bx.implatform.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.bx.implatform.kafka.entity.EventScreenNotice;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
@Tag(name = "门户接口")
public class KafkaTestController {

    private final KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/sendEventScreenNotice")
    @Operation(summary = "kafka测试大屏通知接口", description = "kafka测试大屏通知接口")
    public String sendTestMessage() {
        EventScreenNotice notice = new EventScreenNotice();
        notice.setEventId("123456789");
        notice.setUserId("1945296538560679937");
        notice.setCreateTime(LocalDateTime.now().toString());
        CompletableFuture<SendResult<String, String>> send = kafkaTemplate.send("eventscreennotice", JSON.toJSONString(notice));
        return "Message sent successfully";
    }
}
